import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/widgets/divider/solid_divider.dart";
import "package:flutter/material.dart";

void editGatewayName({
  required BuildContext context,
  required String value,
  ValueChanged<String>? onChange,
}) async {
  String textValue = value;
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return Dialog(
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(10)),
        ),
        child: Container(
          child: ListView(
            shrinkWrap: true,
            children: [
              const Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Padding(
                    padding: EdgeInsets.symmetric(vertical: 10),
                    child: Text("网关名称", style: TextStyle(fontSize: 18),),
                  ),
                ],
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child: TextFormField(
                  autofocus: true,
                  decoration: const InputDecoration(
                    hintText: "请输入",
                    border: InputBorder.none,
                  ),
                  initialValue: textValue,
                  onChanged: (val) {
                    textValue = val;
                  },
                ),
              ),
              const SolidDivider(),
              SizedBox(
                height: 50,
                child: Row(
                  children: [
                    Expanded(
                      child: TextButton(
                        onPressed: () {
                          Navigator.of(context).pop();
                        },
                        child: const Text("取消", style: TextStyle(color: ThemeVars.colorTextTer),),
                      ),
                    ),
                    const SolidDivider(direction: Axis.vertical,),
                    Expanded(
                      child: TextButton(
                        onPressed: () {
                          if (textValue.isEmpty) return;
                          if (onChange != null) onChange(textValue);
                          Navigator.of(context).pop();
                        },
                        child: const Text("确定")
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      );
    }
  );
}